from flask import Flask,Blueprint
from app.mapper.database import init_db
from app.views.test import test_bp
from app.views.user import user_bp
from app.views.stud import stud_bp
import settings
import os
from flask_cors import CORS

def create_app():
    app = Flask(__name__)

    app.config['SECRET_KEY'] = os.urandom(30)  # 替换为你的密钥 #设置了 SECRET_KEY，会话数据会被加密存储，从而保证了数据的安全性。

    # CORS(app, origins= ["http://127.0.0.1:8000"])
    # CORS(app, origins="*")
    CORS(app, origins= ["http://localhost:8000"])

    app.config['SECRET_KEY'] = os.urandom(30)  # 替换为你的密钥

    app.config['SQLALCHEMY_DATABASE_URI'] = settings.DATABASE_URI
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False  # 禁用信号跟踪以提高性能
    app.debug = settings.DEBUG

    init_db(app)

    # app.register_blueprint(user_bp,url_prefix='/user')
    # app.register_blueprint(user_bp)
    app.register_blueprint(test_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(stud_bp)

    # init_route(app)

    return app
